<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Ajax_CheckUser extends Controller{

public function action_exist()
{
	if ($_POST)
	{
		$email = arr::get($_POST, 'email');
		Kohana::$log->add(Log::ERROR, $email);
		if (empty($email))
		{
			echo 'false';
			return;
		}
		if ($this->user_exist($email))
		{
			echo 'true';
			return;
		}
	}
	echo 'false';
}

public function action_notexist()
{
	if ($_POST)
	{
		$email = arr::get($_POST, 'email');
		Kohana::$log->add(Log::ERROR, $email);
		if (empty($email))
		{
			echo 'false';
			return;
		}
		if (!$this->user_exist($email))
		{
			echo 'true';
			return;
		}
	}
	echo 'false';
}

protected function user_exist($email)
{
	$user = ORM::factory('user');
	$user->where('email', '=', $email)->find();
	if ($user->loaded())
	{
		return TRUE;
	}
	return FALSE;
}

}
